clear


	* Identify model with best fit
		forvalues v =1(1)5 {
			qui: insheet using "${data}v5_Parameters_`v'.csv"
			qui: destring v7, replace force
			qui: destring v8, replace force

			qui: su v7 if _n ==1
			qui: global lv`v' : di %4.1f `r(mean)'
			qui: su v8 if _n ==1
			qui: global flag`v' = `r(mean)'

			qui: clear
		}
		qui:set obs 5
		qui:ge loss =.
		qui:ge flag =.

		qui:ge sim = _n
		forvalues v =1(1)5 {
		qui: replace loss = ${lv`v'} if sim == `v'
		qui: replace flag = ${flag`v'} if sim == `v'
		}
		gsort loss sim
		su sim if _n ==1
		global best1 =    `r(mean)'
		

	


	clear

	insheet using "${data}v5_Moments_all_${best1}.csv"
	destring v1, replace force
	qui:  su v1 if _n ==13
	global r13_c2  : di %4.2f `r(mean)'

	qui: su v1 if _n ==14
	global r14_c2 : di %4.3f `r(mean)'

	qui:  su v1 if _n ==15
	global r15_c2 : di %4.3f `r(mean)'
	

	
	clear
	
	insheet using "${data}v5_Parameters_${best1}.csv"
	
	
	
	destring v7, replace force
	su v7 if _n ==1
	local loss1 : di %4.1f `r(mean)'

	keep v2 v3
	drop if _n >12
	rename v2 simulated
	rename v3 real
	destring simulated, replace force
	destring real, replace force
	forvalues v = 1(1)12{
	qui: su simulated if _n == `v'
	local r`v'_c2 : di %4.3f  `r(mean)'
	qui: 	su real if _n == `v'
	local r`v'_c1 : di %4.3f `r(mean)'
	}

	
	#delimit ;	
	file open myfile using "${output}Table8.tex", write replace;
	file write myfile   _n "\begin{tabular}{lcc}"			
	_n "\thickhline"
	_n "Moments &  Targeted Real & Simulated    \\"
	_n "\hline"		
	_n "\mbox{}\\"
	_n " Supervisor effort in worker incentives group & `r1_c1' & `r1_c2'    \\ "	
	_n " Supervisor effort in supervisor incentives group		    &`r2_c1'  & `r2_c2'   \\ "
	_n " Supervisor effort in shared incentives group  & `r3_c1'  & `r3_c2'   \\ "	
	_n " Supervisor effort in control group   &`r4_c1' & `r4_c2' \\	"
	_n " Output in worker incentives group & `r5_c1'  & `r5_c2'   \\ "	
	_n " Output in supervisor incentives group 	    &`r6_c1' & `r6_c2' \\	"
	_n " Output in shared incentives group & `r7_c1'  & `r7_c2'   \\ "	
	_n " Output in control group 	    &`r8_c1' & `r8_c2' \\	"
	_n " \mbox{}\\"
	_n " \hline"
	_n " Value loss function 	    & \multicolumn{2}{c}{`loss1'} \\	"
	_n "\thickhline"
	_n "\end{tabular}" 
	_n " \mbox{}\\" 
	_n "\footnotesize"
	_n " Notes: The table shows the targeted empirical moments used for minimum distance estimation as well as the simulated moments.   ";
	file close myfile;
	#delimit cr
	clear



